<%@page import="com.df.springmvc.workflow.trace.controller.TraceManageController"%>
<%@page import="com.df.springmvc.workflow.trace.services.TraceManageServices"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Page.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<jsp:include page="/scripts/common/index.html"></jsp:include>
<jsp:include page="/scripts/jquery/index.html"></jsp:include>
<jsp:include page="/scripts/dhtmlx/index.html"></jsp:include>
<jsp:include page="/scripts/bootstrap/index.html"></jsp:include>
<link rel="stylesheet" href="${basePath }style/default.css">
<script>
	var myGrid;
	function init() {
		clickFun();
		addNode();
		initData();
		initEvent();
	}
	function initData() {
		query();
	}
	function initEvent() {
	}
	function addNode() {
		var str = "<div id='example5' class='ezmodal'></div><input type='text' id='sucessUrl' style='display:none'/>";
		$("body").append(str);
	}
	function clickFun() {
		//新增
		$("#add").click(function() {
			SN.getWindowByUrl("部署流程", "700", "450", "${basePath}page/workflow/trace/TraceManage/toAdd", {});
		});
		//浏览
		$("#view").click(function() {
			var v1 = getGridSelectValues(2);
			var v2 = getGridSelectValues(3);
			if (v1.length == 1) {
				var processInstanceId = v1;
				var taskId = v2;
				$("#taskId").val(taskId);
				$("#processInstanceId").val(processInstanceId);
				$("#procForm").submit();
			} else {
				SN.alert.error("请选择一条记录");
			}
		});
		//高级查询
		$("#query").click(function() {
			SN.getWindowByUrl("高级查询", "800", "400", "${basePath}common/AdvanceQuery.jsp", {});
		});
		//删除
		$("#delete").click(function() {
			var v = getGridSelectValues(0);
			SN.alert.confirm("是否要删除" + v.length + "流程实例！", function(obj) {
				if (obj) {
					var v = getGridSelectValues(2);
					$.ajax({
							type : 'POST' ,
							url : '${basePath}page/workflow/trace/TraceManage/doDel' ,
							data : {
								"map.guid" : v ,
							} ,
							dataType : "json" ,
							async : true ,
							cache : false ,
							jsonpCallback : "null" ,
							//beforeSend : function(response, status, statusText) {
							//alert(response + ":" + status + ":" + statusText);
							//} ,
							//dataFilter : function(response, status, statusText) {
							//alert(response + ":" + status + ":" + statusText);
							//} ,
							success : function(response, status, statusText) {
								//alert(response + ":" + status + ":" + statusText);
								if (response.status) {
									SN.alert.info(response.content, function() {
										query();
									});
								} else {
									alert(response.content);
								}
							} ,
							error : function(response, status, statusText) {
								//alert(response + ":" + status + ":" + statusText);
							} ,
							complete : function(response, status, statusText) {
								//alert(response + ":" + status + ":" + statusText);
							}
					});
				}
			});
		});
		//重置
		$("#repeat").click(function() {
			window.location.reload();
		});
		//刷新
		$("#refresh").click(function() {
			query();
		});
	}
	//重置查询框
	//重置查询框
	function clearData() {
		$(".query").each(function(key, val) {
			$("#" + val.id).val("");
		});
	}
	function query() {
		var v = getValue();
		$(".query").each(function(key, val) {
			v[val.name] = $("#" + val.id).val();
		});
		$.ajax({
				type : 'POST' ,
				url : 'page/workflow/trace/TraceManage/query' ,
				data : v ,
				dataType : "json" ,
				async : true ,
				cache : false ,
				jsonpCallback : "null" ,
				//beforeSend : function(response, status, statusText) {
				//alert(response + ":" + status + ":" + statusText);
				//} ,
				//dataFilter : function(response, status, statusText) {
				//alert(response + ":" + status + ":" + statusText);
				//} ,
				success : function(response, status, statusText) {
					if (response.status) {
						var a = response.content.currentPageNum;
						var b = response.content.allPageNum;
						var c = response.content.allCount;
						setValue(a, b, c);
					} else {
						alert(response.content);
					}
				} ,
				error : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
				} ,
				complete : function(response, status, statusText) {
					//alert(response + ":" + status + ":" + statusText);
				}
		});
	}
</script>
</head>
<style>
.fv-form-bootstrap .help-block {
	width: 0px;
	height: 0px;
}
</style>
<body onload="init()">
	<div style="display: none;">
		<form id="procForm" action="${basePath}page/workflow/trace/TraceManage/toView" method="post" target="_blank">
			<input value="" id="taskId" name="taskId">
			<input value="" id="processInstanceId" name="processInstanceId">
		</form>
	</div>
	<form class="form-horizontal MyForm" id="MyForm" name="MyForm" method="post" target="MyFrame" enctype="multipart/form-data">
		<table class="listTableClass" border="0" cellpadding="0" cellspacing="0">
			<tr class="queryClass">
				<td>
					<table border="0">
						<tr>
							<td style="width: 400px;" class="contClass">
								<label class="col-xs-3 control-label">流程实例编号：</label>
								<div class="col-xs-8 ">
									<input class="form-control query" type="text" name="map.insId" id="insId" placeholder="" aria-describedby="sizing-addon2">
								</div>
							</td>
							<td style="width: 160px;" class="contClass">
								<label class="col-xs-3 control-label">类型：</label>
								<div class="col-xs-8 ">
									<select class="form-control query" type="text" name="map.type" id="type" placeholder="" aria-describedby="sizing-addon2">
										<option value="crt">当前</option>
										<option value="his">历史</option>
									</select>
								</div>
								<label></label>
							</td>
							<td>
								<button onclick="query()" class="btn btn-primary" type="button">
									<span>查询</span>
								</button>
								<button onclick="clearData()" class="btn btn-primary" type="reset">
									<span>清空</span>
								</button>
							</td>
							<td></td>
						</tr>
					</table>
				</td>
			</tr>
			<tr class="listTrClass">
				<td>
					<table class="listTableClass">
						<tr class="listContClass">
							<td>
								<div>
									<button class="btn btn-primary" type="button" id="view">
										<span class="glyphicon glyphicon-file" aria-hidden="true"></span>
										&nbsp;
										<span>浏览</span>
									</button>
									<button class="btn btn-primary"  type="button" id="delete">
										<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
										&nbsp;
										<span>删除</span>
									</button>
									<button class="btn btn-primary" type="button" id="refresh">
										<span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>
										&nbsp;
										<span>刷新</span>
									</button>
									<button class="btn btn-primary" type="button" id="repeat">
										<span class="glyphicon glyphicon-repeat" aria-hidden="true"></span>
										&nbsp;
										<span>重置</span>
									</button>
								</div>
							</td>
						</tr>
						<tr class="listTrClass">
							<td>
								<jsp:include page="/common/grid_toolbar.jsp">
									<jsp:param value="query" name="func" />
									<jsp:param value="setValue" name="setValue" />
									<jsp:param value="getValue" name="getValue" />
									<jsp:param value="getGrid" name="getGrid" />
									<jsp:param value="getGridSelectValues" name="getGridSelectValues" />
									<jsp:param value="true" name="isPaging" />
								</jsp:include>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
